<div class="deposit-actions well">
  <ul class="list-inline text-right">
    <li class="pull-left">
      <button
        class="btn btn-danger"
        ng-hide="recordsVM.invenioRecordsArgs.templateParams.is_published"
        ng-disabled="recordsVM.invenioRecordsLoading || !recordsVM.invenioRecordsEndpoints.self"
        ng-attr-title="{{(recordsVM.invenioRecordsLoading || !recordsVM.invenioRecordsEndpoints.self) && 'Record was not saved yet.' || 'Delete the deposit'}}"
        ng-click="recordsVM.actionHandler(['self', 'DELETE'], recordsVM.invenioRecordsArgs.templateParams.is_new_version ? 'latest_html' : '/deposit')">
        <i class="fa fa-trash-o fa-inverse"></i> {{ recordsVM.invenioRecordsArgs.templateParams.is_new_version ? 'Discard version' : 'Delete' }}
      </button>
    </li>
    <li class="pull-left">
      <button
        ng-disabled="recordsVM.invenioRecordsLoading"
        ng-hide="!recordsVM.invenioRecordsArgs.templateParams.is_published"
        class="btn btn-warning"
        ng-click="recordsVM.actionHandler(['discard', 'POST'], 'record_html')">
        <i class="fa fa-times icon-white"></i> Discard changes
      </button>
    </li>
    <li ng-show="recordsVM.invenioRecordsLoading"><i class="fa fa-spinner"></i></li>
    <li>
      <button
        ng-disabled="depositionForm.$invalid || recordsVM.invenioRecordsLoading"
        class="btn btn-default"
        ng-attr-title="{{(depositionForm.$invalid || recordsVM.invenioRecordsLoading) && 'You need to fill-in all required fields first' || 'Save the changes'}}"
        ng-click="recordsVM.actionHandler(['self', 'PUT'])">
        <i class="fa fa-file-o"></i> Save
      </button>
    </li>
    <!-- Before publishing the record we also display the warning modal -->
    <li>
      <button
        class="btn btn-primary"
        data-toggle="modal"
        data-target="#warningModal"
        ng-hide="recordsVM.invenioRecordsArgs.templateParams.is_published"
        ng-disabled="depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading || (filesVM.files | checkAllFilesUploaded) || filesVM.files.length == 0"
        ng-attr-title="{{(depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading) && 'You need to save your deposit first' 
        || (filesVM.files | checkAllFilesUploaded) && 'There are pending files to be uploaded' 
        || (filesVM.files.length == 0) && 'You need to upload at least one file' 
        || 'Publish the record'}}">
        <i class="fa fa-check"></i> Publish
      </button>
    </li>
    <li>
      <button
        class="btn btn-primary"
        ng-hide="!recordsVM.invenioRecordsArgs.templateParams.is_published"
        ng-disabled="depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading"
        ng-attr-title="{{(depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading) && 'You need to save your deposit first' || 'Publish the record'}}"
        ng-click="recordsVM.actionHandler(['publish', 'POST'], 'record_html')">
        <i class="fa fa-check"></i> Publish
      </button>
    </li>
  </ul>
</div>

<div class="modal fade" id="warningModal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button class="close" data-dismiss="modal"><span>&times;</span></button>
        <h4 class="modal-title">Warning</h4>
      </div>
      <div class="modal-body">
        <strong>Once the record is published you will no longer be able to change the files in this upload.</strong>
        <br />
        This is because a Digital Object Identifier (DOI) will be registered immediately after publishing.
        You will still be able to update the record's metadata later.
        <br />
        <br />
        If you only want to create a test upload, please do so on <a href="https://sandbox.zenodo.org">Zenodo Sandbox</a>.
      </div>
      <div class="modal-footer">
        <button class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button
          class="btn btn-primary"
          data-dismiss="modal"
          ng-disabled="depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading"
          ng-attr-title="{{(depositionForm.$invalid || depositionForm.$dirty || recordsVM.invenioRecordsLoading) && 'You need to save your deposit first' || 'Publish the record'}}"
          ng-click="recordsVM.actionHandler(['publish', 'POST'], 'record_html')">
          <i class="fa fa-check"></i> I understand
        </button>
      </div>
    </div>
  </div>
</div>
